package com.chinamobile.iot.mqtt.spi.model;


import com.alibaba.fastjson.annotation.JSONField;
import io.netty.buffer.ByteBuf;
import io.netty.buffer.Unpooled;
import io.netty.handler.codec.mqtt.MqttQoS;



/**
 * Created on 2016/12/19.
 *
 * @author stayfool
 */
public class StoredMessage {

    private MqttQoS qos;
    private byte[] payload;
    private String topic;
    private boolean retained;
    private Integer messageId;

    public StoredMessage() {

    }

    public StoredMessage(byte[] message, MqttQoS qos, String topic) {
        this.topic = topic;
        payload = message;
        this.qos = qos;
    }

    public MqttQoS getQos() {
        return qos;
    }

    public byte[] getPayload() {
        return payload;
    }

    public String getTopic() {
        return topic;
    }

    @JSONField(serialize = false, deserialize = false)
    public ByteBuf getMessage() {
        return Unpooled.wrappedBuffer(payload);
    }

    public boolean isRetained() {
        return retained;
    }

    public void setRetained(boolean retained) {
        this.retained = retained;
    }

    public void setQos(MqttQoS qos) {
        this.qos = qos;
    }

    public void setPayload(byte[] payload) {
        this.payload = payload;
    }

    public void setTopic(String topic) {
        this.topic = topic;
    }

    public Integer getMessageId() {
        return messageId;
    }

    public void setMessageId(Integer messageId) {
        this.messageId = messageId;
    }
}
